<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.*,org.goldfish.message_board01.entity.*" %>
<%@ taglib prefix="gfn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8" lang="zh">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言</title>
    <style>
        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            border: 1px solid black;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
        }

        tr:nth-child(even) {
            background-color: #999999;
        }
    </style>
</head>
<body>

<table style="border: blueviolet 2px solid">
    <thead>
    <tr>
        <th>留言标题</th>
        <th>留言时间</th>
        <th>留言人</th>
    </tr>
    </thead>
    <tbody>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

    <c:forEach var="message" items="${messageList}">
        <tr>
            <td>
                <c:if test="${sessionScope.get('loggedIn')=='true'}">
                    <a href="message?id=${message.id}">${message.title}</a>
                </c:if>
                <c:if test="${sessionScope.get('loggedIn')!='true'}">
                    ${message.title}
                </c:if>
            </td>
            <td>${message.time}</td>
            <td>
                <c:set var="sender">
                    ${message.sender}
                </c:set>
<c:choose>
    <c:when test="${requestScope.get(fn:escapeXml(message.sender))==true}">
        <span style="color: green;">(在线)</span>
    </c:when>
    <c:otherwise>
        <span style="color: gray;">(离线)</span>
    </c:otherwise>
</c:choose>
<%--                <c:if test="${!onlineUsers[message.sender]}">--%>
<%--                    <span style="color: green;">(在线)</span>--%>
<%--                </c:if>--%>
<%--                <c:if test="${onlineUsers[message.sender]}">--%>
<%--                    <span style="color: gray;">(离线)</span>--%>
<%--                </c:if>--%>
                    ${message.sender}
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>
<c:choose>
    <c:when test="${sessionScope.get('loggedIn')=='true'}">
        <a href="addMessage">添加新留言</a>
    </c:when>
    <c:when test="${sessionScope.get('loggedIn')==true}">
        <a href="addMessage">--添加新留言--</a>
    </c:when>
    <c:otherwise>
        <a href=".">登录</a>后才能留言
    </c:otherwise>
</c:choose>
<%--<c:if test="${sessionScope.get('logged_in')=='true'}">--%>
<%--    <a href="addMessage">添加新留言</a>--%>
<%--</c:if>--%>
<%--<a href="addMessage">Add New Message</a>--%>
</body>
</html>

